from django import forms

from App.bootstrap import BootStrapForm


class IndexForm(BootStrapForm):
    index_img = forms.ImageField(
        label='轮播图',
    )
    video_index = forms.FileField(
        label='宣传视频'
    )
    info_index = forms.CharField(
        label='公司背景及简介',
    )
    status_index = forms.CharField(
        label='公司地位'
    )

    # 判断视频格式
    def clean_video_index(self):
        file_object = self.cleaned_data.get('video_index')
        if file_object.name.split('.')[-1] not in ['avi', 'wmv', 'mpeg', 'mp4', 'mov', 'rm', 'ram']:
            raise forms.ValidationError('文件格式错误')
        else:
            return file_object
